﻿JUI.AdapterFactory = {

    tagName: "JUI.AdapterFactory",

    getSuitableAdapter: function (params) {

        if (params.dataProvider) this.dataProvider = params.dataProvider;                   //  user    | wsdl  | wcf   | excel
        else this.dataProvider = "user";

        if (params.dataSource) this.dataSource = params.dataSource;
        else this.dataSource = null;

        if (params.dataType) this.dataType = params.dataType;                               //  json    | xml   | csv   | openxml
        else this.dataType = undefined;

        if (params.dataNode) this.dataNode = params.dataNode;
        else this.dataNode = null;

        /** sets the data source **/
        var dataAdapter = null;
        var dataSource = null;
        if (this.dataProvider == "user")
            dataSource = Object.New(JUI.DataSource, params);
        else if (this.dataProvider == "wsdl")
            dataSource = Object.New(JUI.WSDLDataSource, params);
        else {
            JUI.Logger.log.call(this, "Datasource other than user | wsdl not supported yet", JUI.Logger.type.ERROR);
        }

        /** sets the data adapter **/
        params.dataSource = dataSource;
        if (this.dataType == "json")
            dataAdapter = Object.New(JUI.JSONDataAdapter, params);
        else if (this.dataType == "xml")
            dataAdapter = Object.New(JUI.XMLDataAdapter, params);

        return dataAdapter;
    }
}